package org.computeiro.mp3org.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Method;

public class RsrcMgr {
	
	public static String asString(String resourcePath) throws Exception{
		InputStream in = RsrcMgr.class.getResourceAsStream("resources/" + resourcePath);
		
		Writer writer = new StringWriter();
		 
        char[] buffer = new char[1024];
        try {
            Reader reader = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            in.close();
        }
        return writer.toString();
	}
	
	public static void close(Object closeable){
		if(closeable == null){
			return;
		}
		
		try{
			Method m = closeable.getClass().getMethod("flush", Object.class);
			m.invoke(closeable, new Object(){});
		}catch(Exception  ignored){
		}
		
		try{
			Method m = closeable.getClass().getMethod("close", Object.class);
			m.invoke(closeable, new Object(){});
		}catch(Exception  ignored){
		}
	}
	
	public static void main(String[] args) {
	}
	
}
